import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'

export default class Index extends Component {

  static propTypes = {
    todos:PropTypes.array.isRequired,
    changeCheckAll:PropTypes.func.isRequired,
    clearDone:PropTypes.func.isRequired
  }

  render() {
    const {todos,changeCheckAll,clearDone} = this.props
    const total = todos.length
    const doneNum = todos.reduce((pre,current)=>{
      return pre + (current.done?1:0)
    },0)
    return (
      <div className="FooterContainer">
        <div className="leftText">
          <input type="checkbox" checked={doneNum===total&&total!==0} name="" id="selectAll" onChange={changeCheckAll}/>
          {/* react（JSX）中写style样式用两个大括号写 */}
          <label htmlFor="selectAll">已完成{doneNum} <span style={{margin:'0 5px'}}>/</span> 全部{total}</label>
        </div>
        <div className="clearBtn">
          <span onClick={clearDone}>
            清除已完成任务
          </span>
        </div>
        
      </div>
    )
  }
}
